package com.zz.controller;

import com.alibaba.fastjson.JSONObject;
import com.zz.service.IncentiveService;
import com.zz.utils.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

// 开发上量奖励 电子签章
@Slf4j
@RestController
@RequestMapping("/sign/incentive")
public class SignIncentiveController {

    @Autowired
    IncentiveService incentiveService;


    @PostMapping("/updateAccount")
    public ResultUtil updateAccount(@RequestBody JSONObject jsonObject) {
        Integer type = jsonObject.getInteger("type");
        String id = jsonObject.getString("id");
        return incentiveService.updateAccount(type, id);
    }

    @PostMapping("/updateIDCard")
    public ResultUtil updateIDCard(@RequestBody JSONObject jsonObject) {
        String accountId = jsonObject.getString("accountId");
        String id = jsonObject.getString("id");
        Integer type = jsonObject.getInteger("type");
        return incentiveService.updateIDCard(accountId, type,id);
    }

    @GetMapping("/cancelAccount/{accountId}")
    public ResultUtil cancelAccount(@PathVariable String accountId) {
        return incentiveService.cancelAccount(accountId);
    }

    @PostMapping("/electronicSignature")
    public ResultUtil electronicSignatureIncentive(@RequestBody JSONObject jsonObject) {
        String incentiveId = jsonObject.getString("incentiveId");
        String operationId = jsonObject.getString("operationId");
        return incentiveService.electronicSignatureIncentive(incentiveId, operationId);
    }

    @PostMapping("/noticeDeveloperUrl")
    public String noticeDeveloper(@RequestBody String json) {
        // 接口e签宝的回调
        log.info("e签宝的开发上量奖励回调json = " + json);
        /*
        e签宝的回调json = {"flowId":"e897e8056cbe4288afd3044151da8889","timestamp":1677216081709,"action":"PARTICIPANT_MARKREAD","accountId":"32160ce6ca574334b135872fbd856770","thirdPartyUserId":"152104199402251213","order":1,"readTime":"2023-02-24 13:21:21"}
        e签宝的回调json = {"action":"SIGN_FLOW_UPDATE","flowId":"e897e8056cbe4288afd3044151da8889","accountId":"32160ce6ca574334b135872fbd856770","authorizedAccountId":"32160ce6ca574334b135872fbd856770","order":1,"signTime":"2023-02-24 13:22:11","signResult":2,"resultDescription":"签署完成","thirdPartyUserId":"152104199402251213","timestamp":1677216131264}
        e签宝的回调json = e签宝的回调json = {"action":"SIGN_FLOW_FINISH","flowId":"96ae395fc3c040029e1133a56167a98b","businessScence":"zb盐酸纳美芬注射液1ml-0.1mg - 5支-盒.PDF","flowStatus":"2","createTime":"2023-02-24 13:42:50","endTime":"2023-02-24 13:43:46","statusDescription":"完成","timestamp":1677217427206}
       */
        incentiveService.noticeDeveloper(json);

        return "{\"code\":\"200\",\"msg\":\"success\"}";
    }

}
